import ProForm, { ProFormProps } from '@/components/ProForm/index.vue';
import { ComponentPublicInstance, CSSProperties } from 'vue';

export interface BasicForm<T = any> {
  form?: T;
  options: optionsProps<T>[];
  minWidth?: Number;
  labelWidth?: Array<number>;
  visible: boolean;
  title: string;
  width?: string;
  formCols?: number;
  formAttrs?: FormProps;
  /** 禁用字段 */
  disabledPropList?: FormKeys<T>[];
  /** 隐藏字段 */
  hidePropList?: FormKeys<T>[];
  transitionArr?: transitionProp<T>[];
}

export type FormKeys<T> = keyof T;

export interface optionsProps<T = any> {
  type: 'input' | 'select' | 'date-picker' | 'cascader' | 'cascader-panel' | 'time-select' | 'upload';
  label: string;
  prop: FormKeys<T>;
  hide: boolean;
  cols?: number;
  defaultValue?: string | number | boolean | any[] | Date;
  attrs?: attrsProps;
  children?: childrenProps[];
  rules?: FormItemRules[];
  changeMethod?: (params?: T) => void;
  inputMethod?: (params?: T) => void;
  calendarChange?: (params?: T) => void;
  blurFunction?: (params?: T) => void;
}

export interface childrenProps {
  label: string;
  value: string | number;
  type?: 'option';
  children?: childrenProps[];
}
export interface attrsProps {
  placeholder?: string;
  props?: any;
  type?: 'textarea' | 'date' | 'number' | 'month' | 'datetime' | 'dates' | '' | 'daterange';
  valueFormat?: string;
  format?: string;
  start?: string;
  step?: string;
  end?: string;
  style?: CSSProperties;
  loading?: boolean;
  clearable?: Boolean;
  emitPath?: boolean;
  disabled?: Boolean;
  multiple?: Boolean;
  filterMethod?: Function;
  filterable?: Boolean;
  /**当 multiple 和 filter被设置为 true 时，是否在选中一个选项后保留当前的搜索关键词 */
  reserveKeyword?: Boolean;
  /**下拉框时是否允许用户创建新条目 */
  allowCreate?: boolean;
  /**是否在输入框按下回车时，选择第一个匹配项。 需配合 filterable 或 remote 使用 */
  defaultFirstOption?: boolean;
  showAllLevels?: Boolean;
  options?: childrenProps[];
  remote?: Boolean;
  'reserve-keyword'?: Boolean;
  'remote-method'?: (query: string) => void;
  'value-format'?: string;
}
export interface FormProps {
  labelWidth?: string | number;
  labelPosition?: 'left' | 'right' | 'top';
  inline?: boolean;
}
export interface FormItemRules {
  required?: boolean;
  message?: string;
  validator?: Function;
  trigger: 'blur' | 'change';
}

export interface transitionProp<T> {
  newField: FormKeys<T>;
  oldField: string;
}

export type ProFormInstance = Omit<InstanceType<typeof ProForm>, keyof ComponentPublicInstance | keyof ProFormProps>;
